import { Ref, inject, onMounted, onUnmounted } from "vue"
import { LoadingKey } from '@/types/keys';

const useLoading = ()=>{
    let loading : Ref
    const show = ()=>{
        loading.value = true
    }

    const hide = ()=>{
        loading.value = false
    }

    onMounted(()=>{
        loading = inject(LoadingKey)!
    })

    onUnmounted(()=>{
        loading.value = false
    })

    return { show, hide }
}

export default useLoading